#!/usr/bin/env python
#
#       grouped.py
#
#       Copyright 2008 karthikeyan S.<kaarthikeyapreyan@gmail.com>
#
#       This program is free software; you can redistribute it and/or modify
#       it under the terms of the GNU General Public License as published by
#       the Free Software Foundation; either version 2 of the License, or
#       (at your option) any later version.
#
#       This program is distributed in the hope that it will be useful,
#       but WITHOUT ANY WARRANTY; without even the implied warranty of
#       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#       GNU General Public License for more details.
#
#       You should have received a copy of the GNU General Public License
#       along with this program; if not, write to the Free Software
#       Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
#       MA 02110-1301, USA.

import types

def _gathercomponents(module,entity):
    """
    Return a list of the selected
    entity type in the module
    """
    elist=[]
    verify=[]

    if entity=='class':
        verify=[types.ClassType,types.TypeType]
    elif entity=='function':
        verify=[types.FunctionType]

    for member in dir(module):
        mem_attr=getattr(module,member)
        if type(mem_attr) in verify :
            elist.append(member)

    return elist

def _getmethods(modattr,class_,opt=None):
    """
    Private method for analyzemethod
    """
    methlist=[]
    class_attr=getattr(modattr,class_)
    for meth in class_attr.__dict__:
        meth_attr = getattr(class_attr,meth)
        if type(meth_attr) in (types.MethodType,types.UnboundMethodType):
            if opt == 'raw':
                methlist.append(meth_attr.__name__)
            else:
                methlist.append([meth_attr.__name__,class_attr.__name__])
    return methlist

def customprint(entitylist,module,type):
    """
    prints the selected information list
    """
    print "_________________________________________________"
    print "Information on selected Type: %s \n In module: %s"\
        %(type.upper(),module)
    for index,entity in enumerate(entitylist):
        print " %d.  %s "%(index,entity)
    print "-------------------------------------------------"
